package sk.hackcraft.util.date;

public class Time
{
	private final int hours;
	private final int minutes;
	private final int seconds;
	
	public Time(int hours, int minutes, int seconds)
	{
		this.hours = hours;
		this.minutes = minutes;
		this.seconds = seconds;
	}
	
	public Time(int hours, int minutes)
	{
		this(hours, minutes, 0);
	}
	
	public Time(int seconds)
	{
		this.hours = seconds / (60 * 60);
		seconds -= hours * 60 * 60;
		
		this.minutes = seconds / 60;
		seconds -= minutes * 60;
		
		this.seconds = seconds;
	}
	
	public Time(double seconds)
	{
		this((int) Math.round(seconds));
	}

	public int getHours()
	{
		return hours;
	}

	public int getMinutes()
	{
		return minutes;
	}

	public int getSeconds()
	{
		return seconds;
	}
	
	public int toSeconds()
	{
		return seconds + minutes * 60 + hours * 60 * 60;
	}
	
	public int toMinutes()
	{
		return (int) Math.round(seconds/60.0) + minutes + hours * 60;
	}
	
	public Time plus(Time time)
	{
		return new Time(this.toSeconds() + time.toSeconds());
	}
	
	public Time minus(Time time)
	{
		return new Time(this.toSeconds() - time.toSeconds());
	}
	
	@Override
	public String toString()
	{
		return String.format("%02d:%02d:%02d", hours, minutes, seconds);
	}
}
